<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/page/base.jsp"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'index.jsp' starting page</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<script type="text/javascript" src="<%=path%>//manage/js/jquery-1.4.4.min.js"></script>
	<script type="text/javascript">
		//查询所有分类
		function getData(){
			$.ajax({
				url : root+'/produce/listAllCatelog.action',
				method : 'post',
				dataType : 'json',
				success : function(data) {
					$.each(data,function(i,catelog){
						alert(catelog.intCateId+" "+catelog.varCateName);
					});
				},
				error:function(err){
					if(err.responseText!='')
						alert(err.responseText);
					else
						alert("请求失败！");
				}
			});
		}
		
		//应用编辑
		function editData() {
			$.ajax({
				url : root+'/produce/editApp.action',
				method : 'post',
				dataType : 'json',
				data:{'id' : '1'},
				success : function(data) {
					alert(data.intAppId+" "+data.varAppName+" "+data.intAppStyleId);
				},
				error:function(err){
					if(err.responseText!='')
						alert(err.responseText);
					else
						alert("请求失败！");
				}
			});
		}
		
		//更新应用
		function updateData() {
			//中文汉字需编码
			var json = "{'varAppName':'应用Test','varAppImgUrl':'/Test/img.jpg','intAppId':'1'}";
			$.ajax({
				url : root+'/produce/updateApp.action',
				method : 'post',
				dataType : 'json',
				contentType: 'application/json;charset=utf-8',
				data:{'jsonData':encodeURI(encodeURI(json))},
				success : function(data) {
					alert("更新成功");
				},
				error:function(err){
					if(err.responseText!='')
						alert(err.responseText);
					else
						alert("请求失败！");
				}
			});
		}
		
		//保存分类
		function saveApp() {
			//中文汉字需编码
			var json = "{'varCateName':'童装下衣','intEnterpId':'1','intParentCateId':'6','intAppId':'1','varCateImgUrl':'E:/test/img.bpg'}";
			$.ajax({
				url : root+'/produce/saveCatelog.action',
				method : 'post',
				dataType : 'json',
				contentType: 'application/json;charset=utf-8',
				data:{'jsonData':encodeURI(encodeURI(json))},
				success : function(data) {
					alert("保存成功");
				},
				error:function(err){
					if(err.responseText!='')
						alert(err.responseText);
					else
						alert("请求失败！");
				}
			});
		}
		
		//根据ID查询子分类
		function getChildCatelog() {
			$.ajax({
				url : root+'/produce/listChildCatelog.action',
				method : 'post',
				dataType : 'json',
				data:{'id':'6'},
				success : function(data) {
					$.each(data,function(i,catelog){
						alert(catelog.intCateId+" "+catelog.varCateName);
					});
				},
				error:function(err){
					if(err.responseText!='')
						alert(err.responseText);
					else
						alert("请求失败！");
				}
			});
		}
		
		//更新分类
		function updateCatelog() {
			//中文汉字需编码
			var json = "{'intCateId':'7','varCateName':'童装上衣','varCateImgUrl':'/test/update.bpg'}";
			$.ajax({
				url : root+'/produce/updateCatelog.action',
				method : 'post',
				dataType : 'json',
				data:{'jsonData':encodeURI(encodeURI(json))},
				success : function(data) {
					alert("更新成功");
				},
				error:function(err){
					if(err.responseText!='')
						alert(err.responseText);
					else
						alert("请求失败！");
				}
			});
		}
		
		//删除分类
		function deleteCatelog() {
			if(window.confirm("确定删除该分类及所有子分类？")){
				$.ajax({
					url : root+'/produce/deleteCatelog.action',
					method : 'post',
					dataType : 'json',
					data:{'id':'6'},
					success : function(data) {
						alert("删除分类及子分类成功");
					},
					error:function(err){
						if(err.responseText!='')
							alert(err.responseText);
						else
							alert("请求失败！");
					}
				});
			}
		}
		
		//新增或更新分类
		function saveNavigation() {
			//中文汉字需编码
			var saveJson = "{'intNavigateId':'-1','varNavigateName':'Home','intNavigateOrder':'1','intNavigateIconId':'1'}";
			var updateJson = "{'intNavigateId':'1','varNavigateName':'More','intNavigateOrder':'2','intNavigateIconId':'2'}";
			$.ajax({
				url : root+'/produce/savePageNavigation.action',
				method : 'post',
				dataType : 'json',
				data:{'json':updateJson},
				success : function(data) {
					alert("新增或更新成功");
				},
				error:function(err){
					if(err.responseText!='')
						alert(err.responseText);
					else
						alert("请求失败！");
				}
			});
		}
		
		//查询所有导航
		function getAllNavigation(){
			$.ajax({
				url : root+'/produce/viewPageNavigation.action',
				method : 'post',
				dataType : 'json',
				success : function(data) {
					if (data == "-1") {
						alert("没有相关记录");
					}else {
						$.each(data,function(i,navigation){
							alert(navigation.intNavigateId+" "+navigation.varCateName+" "+navigation.intNavigateOrder);
						});
					}
				},
				error:function(err){
					if(err.responseText!='')
						alert(err.responseText);
					else
						alert("请求失败！");
				}
			});
		}
		
		//删除导航
		function deleteNavigation(){
			$.ajax({
				url : root+'/produce/deletePageNavigation.action',
				method : 'post',
				dataType : 'json',
				data:{'id':'1'},
				success : function(data) {
					alert(data);
				},
				error:function(err){
					if(err.responseText!='')
						alert(err.responseText);
					else
						alert("请求失败！");
				}
			});
		}
		
		//保存分类
		function saveCatelogT() {
			//中文汉字需编码
			var json = "{'parentHasSubCate':-1,'catelogInfo':{'intParentCateId':0,'varCateName':'tttttttttttt','varCateImgUrl':'http://localhost:8080/WORKDIR/TEMP/PB2JTLVB9IZ9348X__catelog_icon.png'},'attributeInfo':[{'varAttriName':'ppp'},{'varAttriName':'pp'},{'varAttriName':'pp'}]}";
			$.ajax({
				url : root+'/produce/saveCatelog.action',
				method : 'post',
				dataType : 'json',
				data:{'jsonData':json},
				success : function(data) {
					alert("保存成功");
				},
				error:function(err){
					if(err.responseText!='')
						alert(err.responseText);
					else
						alert("请求失败！");
				}
			});
		}
		
		//保存页面
		function savePageView() {
			//中文汉字需编码
			var json = "[{'viewInfo':{'intModuleStyleId':1,'intResourceId':1,'varViewName':'view1','intViewOrder':1},'catelogs':[{'intCateId':1}]}]";
			$.ajax({
				url : root+'/produce/savePage.action',
				method : 'post',
				dataType : 'json',
				contentType: 'application/json;charset=utf-8',
				data:{'json':json},
				success : function(data) {
					alert("保存成功");
				},
				error:function(err){
					if(err.responseText!='')
						alert(err.responseText);
					else
						alert("请求失败！");
				}
			});
		}
		
		//获取分类属性
		function getAttributes() {
			//中文汉字需编码
			var json = "{'intCateId':1,'intHasSubCate':1}";
			$.ajax({
				url : root+'/produce/viewCateAttributes.action',
				method : 'post',
				dataType : 'json',
				contentType: 'application/json;charset=utf-8',
				data:{'json':json},
				success : function(data) {
					$.each(data,function(i,attr){
						alert(attr.intCateId+" "+attr.intHasSubCate);
					});
				},
				error:function(err){
					if(err.responseText!='')
						alert(err.responseText);
					else
						alert("请求失败！");
				}
			});
		}
		
		//根据ID获取页面内容
		function viewPageContent() {
			//中文汉字需编码
			var json = "{'id':1}";
			$.ajax({
				url : root+'/produce/viewPageContent.action',
				method : 'post',
				dataType : 'json',
				contentType: 'application/json;charset=utf-8',
				data:{'json':json},
				success : function(data) {
					alert(data);
				},
				error:function(err){
					if(err.responseText!='')
						alert(err.responseText);
					else
						alert("请求失败！");
				}
			});
		}
		
		//根据分类内容
		function saveCatelogContent() {
			var json = "{'intCateId':92,'contentInfo':{'varContentName':'Nikon 70D','varContentDescript':'nice camera','varContentImgUrl':'http://img12.360buyimg.com/n2/3835/f4d3aa97-14a8-4602-ba5f-9991fb0c6005.jpg'},'attrInfo':[{'intAttriId':315,'varAttriValue':'30000'},{'intAttriId':316,'varAttriValue':'5'},{'intAttriId':324,'varAttriValue':'Nikon'}],'imgInfo':[{'varImgUrl':'http://img30.360buyimg.com/jgsq-productsoa/g4/M00/06/0F/rBEGFVARF6YIAAAAAAAu1Trft2wAABQ-wG7lj0AAC7t052.jpg','varImgDescrip':'big picture'},{'varImgUrl':'http://img20.360buyimg.com/ImgUpload/vclistimg/201012221931413232010-12-22_192738.jpg','varImgDescrip':'process'}]}";
			$.ajax({
				url : root+'/produce/saveContent.action',
				method : 'post',
				dataType : 'json',
				contentType: 'application/json;charset=utf-8',
				data:{'json':json},
				success : function(data) {
					alert("保存成功");
				},
				error:function(err){
					if(err.responseText!='')
						alert(err.responseText);
					else
						alert("请求失败！");
				}
			});
		}
	</script>
  </head>
  
  <body>
    This is my test page. <br>
    <input type="button" value="获得所有分类" onclick="getData();"/><br/>
   	<input type="button" value="应用编辑" onclick="editData();"/><br/>
   	<input type="button" value="应用更新" onclick="updateData();"/><br/>
   	<input type="button" value="保存分类" onclick="saveApp();"/><br/>
   	<input type="button" value="查询孩子分类" onclick="getChildCatelog();"/><br/>
   	<input type="button" value="更新分类" onclick="updateCatelog();"/><br/>
   	<input type="button" value="删除分类" onclick="deleteCatelog();"/><br/>
   	<input type="button" value="新增或更新导航" onclick="saveNavigation();"/><br/>
   	<input type="button" value="查询所有导航" onclick="getAllNavigation();"/><br/>
   	<input type="button" value="删除导航" onclick="deleteNavigation();"/><br/>
   	<input type="button" value="保存分类T" onclick="saveCatelogT();"/><br/>
   	<input type="button" value="保存页面" onclick="savePageView();"/><br/>
   	<input type="button" value="获取分类属性" onclick="getAttributes();"/><br/>
   	<input type="button" value="获取页面内容" onclick="viewPageContent();"/><br/>
   	
   	<input type="button" value="保存分类内容" onclick="saveCatelogContent();"/><br/>
   	
  </body>
</html>
